Page({
    data: {
        navInfo: '',
        navBarColor: '#fff',
        info: null, //供应商信息
        statistics: null, //统计信息
        customerInfo: null, //客服信息
        pickPointInfo: null, //提货点信息
    },
    onLoad: function(options) {
        this.setData({
            navInfo: getApp().globalData.navInfo
        })
        this.getPickPointInfo()
    },
    onShow() {
        this.getStatistics()
        this.getDetail()
    },
    onReady: function() {
        this._animate()
    },
    /**获取供应商详情信息 */
    getDetail() {
        this.request({
            url: '/supplier/supplier/detail'
        }, res => {
            this.setData({ info: res.data })
        }, res => {
            if (res.code == 13003) {
                this.redirect_login()
            }
        })
    },
    /**获取统计信息 */
    getStatistics() {
        this.request({
            url: '/supplier/index/tongji'
        }, res => {
            this.setData({ statistics: res.data })
        })
    },
    /**配送至地址 */
    getPickPointInfo() {
        this.request({
            url: '/api/index/config?type=3'
        }, res => {
            this.setData({ pickPointInfo: res.data })
        })
    },
    //点击导航
    openLocation() {
        const { lat, lng, house, addr } = this.data.pickPointInfo
        wx.openLocation({
            latitude: Number(lat),
            longitude: Number(lng),
            scale: 14,
            name: house,
            address: addr
        })
    },
    /**退出登录 */
    logout() {
        wx.$dialog.confirm({
            title: '提示',
            message: '您确定退出登录吗？',
            theme: 'round-button',
            confirmButtonColor: 'var(--themColor)',
            cancelButtonColor: '#BDBDBD',
            beforeClose: (action) => new Promise((resolve) => {
                if (action === 'confirm') {
                    this.setData({ info: null, statistics: null, })
                    resolve(true)
                    return this.redirect_login()
                }
                resolve(true)
            })
        })
    },
    _animate() {
        wx.createSelectorQuery().select('#scroller').fields({
            scrollOffset: true,
            size: true,
        }, (res) => {
            this.animate('.white_bar', [{
                opacity: '0'
            }, {
                opacity: '1'
            }], 2000, {
                scrollSource: '#scroller',
                timeRange: 2000,
                startScrollOffset: 0,
                endScrollOffset: 50,
            })
        }).exec()
    },
    onPageScroll({ detail }) {
        if (detail.scrollTop >= 40) {
            if (this.data.navBarColor === '#000') return
            this.setData({ navBarColor: '#000' })
            wx.setNavigationBarColor({
                frontColor: '#000000',
                backgroundColor: '',
                animation: {
                    duration: 400,
                    timingFunc: 'easeIn'
                }
            })
        } else {
            if (this.data.navBarColor === '#fff') return
            this.setData({ navBarColor: '#fff' })
            wx.setNavigationBarColor({
                frontColor: '#ffffff',
                backgroundColor: '',
                animation: {
                    duration: 400,
                    timingFunc: 'easeIn'
                }
            })
        }
    }
})